package com.example.myapplication.ui.fragment

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.example.myapplication.request.CollectRequest
import com.example.myapplication.request.SquareRequest
import kotlinx.coroutines.launch

/**
 *广场的viewModel
 *
 * @author : Kun
 * @date : 2021/6/10
 * @time : 9:52
 */
class SquareViewModel :ViewModel() {
    /**
     * 广场相关的请求
     */
    val squareRequest =SquareRequest()

    /**
     * 收藏相关的request
     */
    val collectRequest = CollectRequest()

    /**
     * 请求广场文章数据
     */
    fun requestArticleList(index: Int) {
        viewModelScope.launch {
            squareRequest.requestSquareArticleList(index)
        }
    }

    /**
     * 新增文章收藏
     */
    fun requestAddCollectArticle(id: Int) {
        viewModelScope.launch {
            collectRequest.requestAddCollectArticle(id)
        }
    }

    /**
     * 取消文章收藏
     */
    fun requestDelCollectArticle(id: Int) {
        viewModelScope.launch {
            collectRequest.requestDelCollectArticle(id)
        }
    }
}